<template>
    <section>
      <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        >
        <el-table-column  label='序号' align="center" width="80px">
          <template slot-scope="scope">
              <span style="margin-left: 10px">{{Number(scope.$index)+1}}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-for="(val,key) in tableTitle"
          :prop="key"
          :label="val"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column  label='操作' align="center">
          <template slot-scope="scope">
                   <span style="margin-left: 10px" @click="detail(scope)" ><img src="../../../images/server03.png"/></span>
                   <span style="margin-left: 10px" @click="updata(scope)" ><img src="../../../images/server02.png"/></span>
                   <span style="margin-left: 10px" @click="del(scope)"  ><img src="../../../images/server04.png"/></span>
          </template>
        </el-table-column>
    </el-table>

    <p style="margin-top: 15px;">
        <el-pagination
        background
        layout="prev, pager, next"
              @current-change="handleCurrentChange"
        :total="pageTotal">
      </el-pagination>
    </p>
    </section>
</template>

<script>
    import {organizationDataExchangeDel,
            organizationDataExchangeListSearch
    } from '../../api/data-exchange-api.js'
    export default {
        props:{
          tableTitle:Object,
          tableData:Array,
          detailObjid:Object,
          pageTotal:Number,
          organization:Object
        },
        data() {
          return {

          };
        },
        methods: {
          detail(scope){
            this.$emit('detail',scope);
                // console.log(scope)
          },
          updata(scope){
          this.$emit('updata',scope);
          },
          del(scope){
             this.$confirm('是否删除?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
                    organizationDataExchangeDel({},scope.row.code);     //删除具体某条组织信息
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              setTimeout(()=>{
                  organizationDataExchangeListSearch(this.organization).then(res => {
                      const result = res.data.data.list;
                      this.tableData = [];
                      for(let i=0 ; i < result.length; i++ ){
                          let obj = {};
                          let resultType = '';
                          let resultState = '';
                          if(result[i].producerType == 1){
                              resultType = '服务方'
                          }else if(result[i].producerType == 0){
                              resultType = '请求方'
                          }else{
                              resultType = '服务方/请求方'
                          }
                          resultState = result[i].status ? '是' : '否';
                          obj.code = result[i].id;
                          obj.oragion = result[i].name;
                          obj.type = resultType;
                          obj.state = resultState;
                          this.tableData.push(obj);
                          console.log('hhhhhhhhh');
                          console.log(this.tableData)
                      }
                  })
              },500)
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              });
            });
          },
            listSearch(){

            },
            handleCurrentChange(val){       //页码选择时候重新获取组织信息列表
                console.log(val+'页')
                this.organization.pageSize = 10;
                this.organization.pageNum = val;
                organizationDataExchangeListSearch(this.organization).then(res => {
                    const result = res.data.data.list;
                    this.tableData = [];
                    for(let i=0 ; i < result.length; i++ ){
                        let obj = {};
                        let resultType = '';
                        let resultState = '';
                        if(result[i].producerType == 1){
                            resultType = '服务方'
                        }else if(result[i].producerType == 0){
                            resultType = '请求方'
                        }else{
                            resultType = '服务方/请求方'
                        }
                        resultState = result[i].status ? '是' : '否';
                        obj.code = result[i].id;
                        obj.oragion = result[i].name;
                        obj.type = resultType;
                        obj.state = resultState;
                        this.tableData.push(obj);
                    }
                })
            }
        },
        mounted(){
        }
    };
</script>

<style scoped="scoped">

</style>
